#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define FILELOCAL "X:\\test2.txt"

int main()
{
    FILE *fp;
    char poem[4][10],temp[10];
    int i,j,k,n=4;//四句诗
    printf("please enter the English Poem\n");
    for(i=0;i<n-1;i++)
    {
        gets(poem[i]);
    }
    for(i=0;i<n-1;i++)
    {
        k=i;
        for(j=i+1;j<i;j++)
        {
            if (strcmp(poem[k],poem[i])>0) k=j;
            if(k!=i)
            {
                strcpy(temp,poem[i]);
                strcpy(poem[i],poem[k]);
                strcpy(poem[k],temp);
            }
            
        }
    }
    if((fp=fopen(FILELOCAL,"w"))==NULL)
    {
        printf("can not open the file.\n");
        exit(0);//调用此函数必须要引入#include<stdlib.h>头
    }
    printf("The poem sequence is:\n");
    for(i=0;i<n;i++)
    {
        fputs(poem[i],fp);
        fputs("\n",fp);
        printf("%s\n",poem[i]);
    }
    return 0;
}